import { RecordStatusEnums } from '../../constants/enums'

export const RECORD_STATUS_OPTIONS = RecordStatusEnums.options // 单据状态下拉options

export const RECORD_STATUS_VALUES = RecordStatusEnums.values // 单据状态枚举值

export const FORM_ITEMS = [
  {
    prop: 'planNo',
    label: '开发计划单号',
    type: 'input'
  },
  {
    prop: 'planName',
    label: '开发计划名称',
    type: 'input'
  },
  {
    prop: 'status',
    label: '计划状态',
    type: 'select',
    options: RECORD_STATUS_OPTIONS,
    clearable: true
  },
  {
    prop: 'devAreaName',
    label: '开发区域',
    type: 'input'
  },
  {
    prop: 'createTime',
    label: '创建日期',
    type: 'datePicker',
    valueFormat: 'yyyy-MM-dd HH:mm:ss',
    timeKeys: ['createOpeTimeLeft', 'createOpeTimeRight']
  },
  {
    prop: 'sponsorName',
    label: '发起人',
    type: 'input'
  },
  {
    prop: 'sponsorDeptName',
    label: '发起部门',
    type: 'input'
  },
  {
    prop: 'startTime',
    label: '计划开始时间',
    type: 'datePicker',
    valueFormat: 'yyyy-MM-dd HH:mm:ss',
    timeKeys: ['startTimeLeft', 'startTimeRight']
  },
  {
    prop: 'endTime',
    label: '计划结束时间',
    type: 'datePicker',
    valueFormat: 'yyyy-MM-dd HH:mm:ss',
    timeKeys: ['endTimeLeft', 'endTimeRight']
  }
]

export const TABLE_COLUMNS = [
  {
    title: '开发计划单号',
    key: 'planNo',
    width: 150
  },
  {
    title: '开发计划名称',
    key: 'planName'
  },
  {
    title: '单据状态',
    key: 'statusStr',
  },
  {
    title: '创建日期',
    key: 'createOpeTime',
    width: 150
  },
  {
    title: '发起人',
    key: 'sponsorName'
  },
  {
    title: '发起部门',
    key: 'sponsorDeptName'
  },
  {
    title: '开发人',
    key: 'developerName'
  },
  {
    title: '开发部门',
    key: 'devDeptName',
    width: 150
  },
  {
    title: '开发区域',
    key: 'devAreaName'
  },
  {
    title: '归属中心',
    key: 'belongCenterName'
  },
  {
    title: '计划开始时间',
    key: 'startTime',
    width: 150
  },
  {
    title: '计划结束时间',
    key: 'endTime',
    width: 150
  },
  {
    title: '计划说明',
    key: 'note'
  },
  {
    title: '品类树',
    key: 'categoryPath',
    width: 300
  },
  {
    title: '品牌',
    key: 'brandName'
  },
  {
    title: '计划进展状态',
    key: 'progressStatusStr'
  },
  {
    title: '开发结果',
    key: 'result'
  },
  {
    title: '供应商考察单号',
    key: 'supplierInspectionNo'
  },
]

// 获取单据状态列
export const getStatusColumn = callback => {
  const statusCol = {
    title: '单据状态',
    width: 150,
    render: (h, { row }) => row.status == RECORD_STATUS_VALUES.ToAudit
      ? <el-button type="text" onClick={() => { callback(row) }}>{row.statusStr}</el-button>
      : <span>{ row.statusStr }</span>
  }
  return statusCol
}

// 获取供应商考察单列
export const getSupplierInspectionNoColumn = callback => {
  const ulStyle = `maxHeight: 300px; overflow: hidden; overflow-y: auto;`
  const liStyle = `padding: 0px 5px; border-bottom: 1px dashed #ccc;`
  const supplierInspectionNoCol = {
    title: '供应商考察单',
    width: 150,
    notShowTip: true,
    render: (h, { row }) => {
      const inspectionNos = row.supplierInspectionNos?.split(',') ?? []
      return (
        <el-popover
          placement="left"
          width="200"
          trigger="hover"
        >
          <ul style={ulStyle}>{
            inspectionNos.map(item => {
              return (<li style={liStyle}>
                <el-button size="mini" type="text" onClick={() => { callback(item) }}>{item}</el-button>
              </li>)
            })
          }</ul>
          <span slot="reference">{row.supplierInspectionNos ?? ''}</span>
        </el-popover>
      )
    }
  }
  return supplierInspectionNoCol
}
